Vectors
let a = vec![1,2,3,4];
let b:Vec<i32>=Vec::new();
- The true form of Vector is a Structure type. So when you define vector, you can use Vec::new() function, just like defining any new structure.
2026-10-04 13:50
String
- Rust stores string in 3 types: vector of u8(eg. 'e'=[101]), char ['ก',' ็'], grapheme cluster['ส', 'วั', 'ส', 'ดี']
- Rust mostly doesn't allow to call String by index because most UTF-8 characters have 2-4 bytes which require 2-4 index to work properly.
- The better way is calling it by character, grapheme by combining it with
for and method .chars() and .bytes()
for c in "สวัสดี".chars(){
println!("{c}");
}
for c in "สวัสดี".bytes(){
println!("{c}");
}
HashMap
- HashMap type is the
key:value storage of data
- It's not use so much, so it's not on a default command lists in the std library, but can be used by defining it with
use command
use std::collections::HashMap;
let mut scores=HashMap::new();
scores.insert(String::from('blue'), 10);
scores.insert(String::from('red'), 20);
for(key, value) in scores{
println!("{key}:{value}");
}